<?php
	session_start();
	require('../Model/mysql.php');
	require('../host_config.php');
?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
</html>
<?php
	$CheckTime = date("Y-m-d H:i");
	$mysql = new MySQL();
    $link = $mysql->connect($mysql_host, $mysql_user, $mysql_passwd, $mysql_db);
    $account = $mysql->real($_POST["account"]);
	//$account = $_POST["account"];          //varchar(30)
	//$account = mysql_real_escape_string($account);
    $length = strlen($account);
    if ($length == 0) { 
		echo "<script language='javascript'>";
		echo "alert('帳號不得為空');";
		echo "history.back();";
		echo "</script>";
		die();
    }
	//$sql = "select * from register where account = '$account'";
    $sql = "select * from LoginUser where account = '$account'";
	$row = $mysql->query_row($sql, $link);
	if ($row != NULL) {
		echo "<script language='javascript'>";
		echo "alert('此帳號已經有人使用了');";
		echo "history.back();";
		echo "</script>";
		die();
	}
	$password_1 = $mysql->real($_POST["password_1"]);
	//$password_1 = $_POST["password_1"];          //varchar(30)
	//$password_1 = mysql_real_escape_string($password_1);
	$length = strlen($password_1);
	if ($length == 0) {
		echo "<script language='javascript'>";
		echo "alert('密碼不得為空');";
		echo "history.back();";
		echo "</script>";
		die();
	}
	$password_2 = $mysql->real($_POST["password_2"]);
	//$password_2 = $_POST["password_2"];          //varchar(30)
	//$password_2 = mysql_real_escape_string($password_2);
	$length = strlen($password_2);
	if ($length == 0) {
		echo "<script language='javascript'>";
		echo "alert('重複密碼不得為空');";
		echo "history.back();";
		echo "</script>";
		die();
    }
	if ($password_1 != $password_2) {
		echo "<script language='javascript'>";
		echo "alert('密碼不相同');";
		echo "history.back();";
		echo "</script>";
		die();
    }
	$temp = "\x0a";
    $temp = $password_1.$temp;
    $password = sha1($temp);
	/*$name = $_POST["ShopName"];          //varchar(30)
	$name = mysql_real_escape_string($name);
	$length = strlen($name);
	if ($length > 30) {
		echo "<script language='javascript'>";
        	echo "alert('店家名稱字數大於10個字');";
        	echo "history.back();";
        	echo "</script>";
        	die();
	}else if ($length == 0) {
        	echo "<script language='javascript'>";
            	echo "alert('店家名稱不得為空');";
            	echo "history.back();";
            	echo "</script>";
            	die();
        }
	$sec_name = $_POST["sec_name"];          //varchar(20)
        $sec_name = mysql_real_escape_string($sec_name);
        $length = strlen($sec_name);
        if ($length > 20) {
        	echo "<script language='javascript'>";
        	echo "alert('分店名稱字數大於6個字');";
        	echo "history.back();";
        	echo "</script>";
        	die();
        }else if ($length == 0) {
        	echo "<script language='javascript'>";
        	echo "alert('分店名稱不得為空');";
        	echo "history.back();";
        	echo "</script>";
        	die();
        }
	if ($sec_name == "無" || $sec_name == NULL)
		$all_name = $name;
	else
		$all_name = $name.$sec_name;*/
    $email = $mysql->real($_POST["email"]);
	//$email = $_POST["email"];    //varchar(60)
	//$email = mysql_real_escape_string($email);
	if (!preg_match("/@/i", $email)) {
		echo "<script language='javascript'>";
		echo "alert('E-mail 格式有誤');";
		echo "history.back();";
		echo "</script>";
		die();
	}
	$length = strlen($email);
	if ($length == 0) {
		echo "<script language='javascript'>";
		echo "alert('e-mail不得為空');";
		echo "history.back();";
		echo "</script>";
		die();
	}
	/*$sql = "select all_name from android where all_name = '$all_name'";
	$row = $mysql->query_row($sql, $link);
	if ($row[0] != NULL) {
        	echo "<script language='javascript'>";
                echo "alert('店名重複');";
                echo "history.back();";
                echo "</script>";
                die();
        }*/
	//$sql = "INSERT INTO register VALUES (NULL, '$account', '$password', '$all_name', '$email', '0', '$CheckTime')";
	$sql = "INSERT INTO LoginUser VALUES (NULL, '$account', '$password', '$email', NULL, '0')";
	$mysql->query($sql, $link);
	header("location:thanks.php");
?>

